home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
MiscKit1.7.1
/
MiscKit
/
Examples
/
MiscPriorityQueue
/
queuetest.m
< prev
next >
Wrap
Text File
|
1994-01-07
|
2KB
|
120 lines
/* NAME:
** QueueTest.m
**
** COPYRIGHT 1992 BY ONYSCHUK AND ASSOCIATES
** ALL RIGHTS RESERVED.
**
** REVISION HISTORY:
** Sun Aug 23 21:10:26 EDT 1992 Mark Onyschuk
** Starting point
**
** DESCRIPTION:
** Program to demonstrate and put the MiscPriorityQueue class
** to the test.
*/
#define NELEM 10
#import <misckit/misckit.h>
void prioritize(void)
{
int i;
id queue;
id obj;
unsigned int priority;
queue = [[MiscPriorityQueue alloc] init];
printf("Queueing and dequeueing Objects:\n\n");
for (i = NELEM; i > 0; i--)
{
obj = [[Object alloc] init];
priority = random() % NELEM;
printf("Queueing object %p with priority %d\n", obj, priority);
[queue addObject:obj withPriority:priority];
}
printf("\n");
for (i = NELEM; i > 0; i--)
{
obj = [queue removeObject];
printf("Dequeued object %p\n", obj);
}
}
void copyqueue(void)
{
int i;
id queue;
id copyA;
id copyB;
id copyC;
id copyD;
id obj;
unsigned int priority;
queue = [[MiscPriorityQueue alloc] init];
printf("Copying Objects:\n\n");
for (i = NELEM; i > 0; i--)
{
obj = [[Object alloc] init];
priority = random() % NELEM;
printf("Queueing object %p with priority %d\n", obj, priority);
[queue addObject:obj withPriority:priority];
}
printf("Copying queue to copyA, copyB, copyC, and copyD.\n");
copyA = [queue copy];
copyB = [queue copy];
copyC = [queue copy];
copyD = [queue copy];
for (i = NELEM; i > 0; i--)
{
priority = [queue highestPriority];
obj = [queue removeObject];
printf("Dequeued object %p (orig.) with priority %d\n", obj, priority);
}
for (i = NELEM; i > 0; i--)
{
priority = [copyA highestPriority];
obj = [copyA removeObject];
printf("Dequeued object %p (copyA) with priority %d\n", obj, priority);
}
printf("copyB %s copyC\n", ([copyB isEqual:copyC]) ? "==" : "!=");
printf("removing last item from copyD\n");
[copyD removeObject];
printf("copyC %s copyD\n", ([copyC isEqual:copyD]) ? "==" : "!=");
}
void main(void)
{
prioritize();
printf("\n");
copyqueue();
}